import {Injectable} from '@angular/core';
import {HttpService} from "./http.service";
import {Observable, of} from "rxjs";
import {Book} from "../store/models/book.model";

interface User {
  id: number;
  name: string;
  email: string;
}

@Injectable({
  providedIn: 'root'
})
export class Service {

  constructor(public http: HttpService) {
  }

  getAll(): Observable<any> {
    return this.http.reqGet('/getAllList')
  }

  getBooks(): Observable<Book[]> {
    return this.http.reqGet<Book[]>('/getBooks');
  }

  addBook(book: Book): Observable<Book> {
    return this.http.reqPost<Book>('/addBooks', book);
  }

  deleteBook(id: number): Observable<{}> {
    const url = `/delBooks/${id}`;
    return this.http.reqGet(url);
  }

  getUsers(): Observable<{users: User[]}> {
    return this.http.reqGet<{users: User[]}>('/getUsers');
    // return of([{
    //   id: 1,
    //   name: "zhangsan",
    //   email: '111@qq.com',
    // }, {
    //   id: 2,
    //   name: "lisi",
    //   email: '222@qq.com',
    // }])
  }
  getPosts(): Observable<any> {
    return this.http.reqGet<any>('/post');
  }
}
